package com.loe.mvp.util

import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.widget.Toast
import com.loe.mvp.R
import com.loe.mvp.ext_app.px
import kotlinx.android.synthetic.main.default_sys_toast.view.*

object SystemToast
{
    private var mToast: Toast? = null

    @JvmStatic
    fun toast(mContext: Context, text: CharSequence)
    {
        mToast?.cancel()
        mToast = Toast(mContext.applicationContext)

        val view = LayoutInflater.from(mContext.applicationContext).inflate(R.layout.default_sys_toast, null)
        val textView = view.textView
        textView.text = text

        mToast?.view = view
        mToast?.duration = Toast.LENGTH_SHORT
        mToast?.setGravity(Gravity.BOTTOM or Gravity.FILL_HORIZONTAL, 0, px(90))

        mToast?.show()
    }

    @JvmStatic
    fun toast(mContext: Context, resId: Int)
    {
        toast(mContext, mContext.resources.getString(resId))
    }
}